import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.util.ArrayList;

public class BackgroundPanelView extends JPanel {

	int counter = 0;
	Image displayImage;
	ArrayList<ImageIcon> backgroundImage = new ArrayList<ImageIcon>();

	public BackgroundPanelView() {
		intializeBackgroundImage();
		setImage(backgroundImage.get(counter));
		this.setPreferredSize(new Dimension(Toolkit.getDefaultToolkit()
				.getScreenSize().width, Toolkit.getDefaultToolkit()
				.getScreenSize().height));
	}

	public void intializeBackgroundImage() {
		File imageFolder = new File("image/background/");
		File[] allBackground = imageFolder.listFiles();
		for (File background : allBackground) {
			if (!background.getName().equals(".svn")) {
				backgroundImage.add(new ImageIcon("image/background/"
						+ background.getName()));
			}
		}
	}

	@Override
	public void paintComponent(Graphics g) {
		g.drawImage(getImage(), 0, 0, getWidth(), getHeight(), this);
	}

	public void setImage(ImageIcon imageIcon) {
		displayImage = imageIcon.getImage();
	}

	public Image getImage() {
		return displayImage;
	}

}
